<div class="layuimini-main">
	<div class="layui-form layuimini-form">
		<div class="layui-form-item">
			<label class="layui-form-label required">用户名</label>
			<div class="layui-input-block">
				<input type="text" name="user_name" disabled readonly value="" class="layui-input">
				<tip>填写自己管理账号的名称。</tip>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label required">昵称</label>
			<div class="layui-input-block">
				<input type="text" name="real_name" lay-verify="required" lay-reqtext="昵称不能为空" placeholder="请输入昵称" value="" class="layui-input">
				<tip>填写自己管理账号的名称。</tip>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label required">手机</label>
			<div class="layui-input-block">
				<input type="number" name="phone" disabled readonly value=""
				 class="layui-input">
			</div>
		</div>
		
		<div class="layui-form-item">
			<label class="layui-form-label">角色</label>
			<div class="layui-input-block">
				<div id ="role_select"></div>
			</div>
		</div>
		<div class="layui-form-item layui-form-text">
			<label class="layui-form-label">备注信息</label>
			<div class="layui-input-block">
				<textarea name="remark" class="layui-textarea" placeholder="请输入备注信息"></textarea>
			</div>
		</div>

		<input name="pid" type="hidden" />
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
			</div>
		</div>
	</div>
</div>
<script>
	layui.use(['form', 'table', 'hsw'], function() {
		var form = layui.form,
			layer = layui.layer,
			table = layui.table,
			hsw = layui.hsw,
			$ = layui.$;
		
		// 当前弹出层，防止ID被覆盖
		var parentIndex = layer.index;

		//监听提交
		form.on('submit(saveBtn)', function(data) {
			
					console.log(data);
			hsw.hsw_post(HSW_API_MANAGE_USER_EDIT.replace('pid',data.field.pid), data.field, function(data) {

					layer.msg('操作成功，即将刷新页面', {
						time: 3000 //
					}, function() {
						hsw.hsw_html_reload(0);
					});

					// 关闭弹出层
					layer.close(index);
					layer.close(parentIndex);

			});
			return false;
		});
		
		window.editInit = function(data){
			
			$('input[name="pid"]').attr('value',data.pid);
			$('input[name="real_name"]').attr('value',data.real_name);
			$('textarea[name="remark"]').val(data.remark);
			$('input[name="user_name"]').attr('value',data.user_name);
			$('input[name="phone"]').attr('value',data.phone);
			
			/* 初始化select*/
			hsw.hsw_post(HSW_API_MANAGE_ROLE_SELECT, {}, function(select) {
				console.log(data.role_list)
				
				
				var initArray = new Array();
				for(var x in data.role_list){
					
					initArray[x] = data.role_list[x].pid;
				}
							
				hsw.hsw_double_select("role_select","role_pid","请选择角色",select,initArray);
				
				form.render();
			});
			
		}
	});
</script>
